//
//  CountBtn.m
//  AiBao
//
//  Created by wanshangwl on 2018/3/26.
//  Copyright © 2018年 Mac. All rights reserved.
//

#import "CountBtn.h"

@implementation CountBtn {
    UIButton *smsButton;
}

- (void)timeDown {
    UIColor *color = self.backgroundColor;
    __block int num = 59;
    dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
    dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC, 0);
    dispatch_source_set_event_handler(timer, ^{
        if (num == 0) {
            self.userInteractionEnabled = YES;
            self.backgroundColor = color;
            [self setTitle:@"发送验证码" forState:UIControlStateNormal];
            dispatch_cancel(timer);
        }else {
            self.userInteractionEnabled = NO;
            [self setTitle:[NSString stringWithFormat:@"重新获取(%d)",num] forState:UIControlStateNormal];

            num--;
        }
    });
    dispatch_resume(timer);
}

@end
